<?php
/* phpYahooSearch Class 1.0.0
 * Written by Jay Denis (jay@gotfoo.org)
 * Google Project Page: http://code.google.com/p/phpyahoo/
 * Released under GNU Lesser General Public License (http://www.gnu.org/copyleft/lgpl.html)
 * For more information about the class and upcoming tools and toys using it,
 * visit hhttp://phpYahoo.gotfoo.org or http://code.google.com/p/phpyahoo/
 *
 *     Please submit all issues to the project page:
 *         http://code.google.com/p/phpyahoo/issues/list
 * 
 
 */

class phpYahooSearch extends phpYahoo {
	
	
	var $base_url = 'http://search.yahooapis.com/';
	var $command_web_search = 'WebSearchService/V1/webSearch';
	var $command_video_search = 'VideoSearchService/V1/videoSearch';
	var $command_related_search = 'WebSearchService/V1/relatedSuggestion';
	var $command_image_search = 'ImageSearchService/V1/imageSearch';
		
	
			
    
    function request_web_search ($params)     {   
	    $xml = $this->request($this->base_url.$this->command_web_search,$params);	
	    $results = array();
		$i = 0;    
		
		foreach($xml->Result as $result){				
			
			$results[$i] = array("title"=>$result->Title,"summary"=>$result->Summary,"url"=>$result->Url,"clickUrl"=>$result->ClickUrl,"displayUrl"=>$result->DisplayUrl,"modificationDate"=>$this->formatDate($result->ModificationDate),"mimeType"=>$result->MimeType);
			$i++;				
		}		
		
		//return array("resultSet"=>$resultSet,"results"=>$results);
		return $results;
    }
    
    function request_related_search ($params)     {   
	    $xml = $this->request($this->base_url.$this->command_related_search,$params);	    
		$results = array();
		$i = 0;
		foreach($xml as $result){			
			$results[$i] = array("result"=>$result->Result);
			$i++;				
		}
		return $results;
    }
    
	function request_video_search ($params)     {   
	    $xml = $this->request($this->base_url.$this->command_video_search,$params);	    
		$results = array();
		$i = 0;
		foreach($xml->Result as $result){			
			$results[$i] = array("title"=>$result->Title,"summary"=>$result->Summary,"url"=>$result->Url,"clickUrl"=>$result->ClickUrl,"refererUrl"=>$result->RefererUrl,"fileSize"=>$result->FileSize,"fileFormat"=>$result->FileFormat,"weight"=>$result->Height,"width"=>$result->Width,"duration"=>$result->Duration,"streaming"=>$result->Streaming,"thumbnail"=>$result->Thumbnail->Url,"theight"=>$result->Thumbnail->Height,"twidth"=>$result->Thumbnail->Width);
			$i++;				
		}	
		
		return $results;
    } 
    
    function request_image_search ($params)     {   
	    $xml = $this->request($this->base_url.$this->command_image_search,$params);	    
		$results = array();
		$i = 0;
		foreach($xml->Result as $result){			
			$results[$i] = array("title"=>$result->Title,"summary"=>$result->Summary,"url"=>$result->Url,"clickUrl"=>$result->ClickUrl,"refererUrl"=>$result->RefererUrl,"fileSize"=>$result->FileSize,"fileFormat"=>$result->FileFormat,"weight"=>$result->Height,"width"=>$result->Width,"thumbnail"=>$result->Thumbnail->Url,"theight"=>$result->Thumbnail->Height,"twidth"=>$result->Thumbnail->Width);
			$i++;				
		}	
		
		return $results;
    } 
    
    function searchWeb($params){
		//http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=madonna&results=2   		       
				
   		$response =  $this->request_web_search($params);//$this->createQueryString($query,$params));
       	return $response;
    }
    
    
    
    function searchRelated($params){
		//http://search.yahooapis.com/WebSearchService/V1/webSearch?appid=YahooDemo&query=madonna&results=2   		        
   		$response =  $this->request_related_search($params);
       	return $response;
    }
    
    
    
	function searchVideos($params){
		//http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=madonna&results=2   		
		
      	$response =  $this->request_video_search($params);       
       	return $response;
    }
    
    function searchImages($params){
		//http://search.yahooapis.com/VideoSearchService/V1/videoSearch?appid=YahooDemo&query=madonna&results=2   		
		
      	$response =  $this->request_image_search($params);       
       	return $response;
    }
}

?>